from pathlib import Path
from core.detector import BaseOSDetector

class ArchDetector(BaseOSDetector):
    """Arch Linux 系统检测模块"""
    
    def detect(self) -> bool:
        """检测是否为 Arch Linux 系发行版"""
        return (
            self._check_os_release_id("arch") or
            Path("/etc/arch-release").exists()
        )

    def get_version(self) -> str:
        """获取 Arch 版本信息 (滚动发行版返回空)"""
        os_release = self.get_os_release()
        # 处理 Manjaro 等衍生版
        if "manjaro" in os_release.get("ID", ""):
            return os_release.get("VERSION_ID", "rolling")
        return "rolling"  # 标准 Arch 无固定版本号

    @staticmethod
    def _check_os_release_id(target_id: str) -> bool:
        """检查 /etc/os-release 中的发行版 ID"""
        os_release = Path("/etc/os-release")
        if not os_release.exists():
            return False
        return any(
            line.strip().lower() == f'id="{target_id}"'
            for line in os_release.read_text().splitlines()
        )